#include <iostream>
#include <queue>

#define N 510
int m, n; int map[N][N];    int ans = 0;
char tmp;
const int dx[] = {0, 1, -1, 0, 0};
const int dy[] = {0, 0, 0, -1, 1};

using namespace std;

void bfs(int x, int y){
    queue< pair<int, int> > q;
    q.push(make_pair(x, y));
    while(!q.empty()){
        int xx = q.front().first; int yy = q.front().second;    q.pop();
        map[xx][yy] = 2;
        for(int i = 1; i <= 4; i++){
            int xxx = xx + dx[i];   int yyy = yy + dy[i];
            if(xxx < 0 || yyy < 0 || xxx > m+1 || yyy > n+1 || map[x][y]){
                continue;
            }
            q.push(make_pair(xxx, yyy));
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> m >> n;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            cin >> tmp;
            if(tmp == '0')  map[i][j] = 0;
            else map[i][j] = 1;
        }
    }
    bfs(0, 0);
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(map[i][j] == 0)  ans++;
        }
    }
    cout << ans << endl;
    return 0;
}